package story;

import static java.util.Arrays.asList;
import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;

import java.util.List;

import org.forex.impl.engine.HistorySteps;
import org.forex.impl.engine.InstrumentSteps;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.junit.runner.RunWith;

import de.codecentric.jbehave.junit.monitoring.JUnitReportingRunner;

@RunWith(JUnitReportingRunner.class)
public class SimpleJBehave extends JUnitStories{

	private Configuration configuration;
	
	public SimpleJBehave(){
		super();
		//this.configuredEmbedder().candidateSteps().add(new ExampleSteps());
		
//		configuration=new Configuration() {
//		};
//		configuration.useFailureStrategy(new RethrowingFailure());
//		configuration.useKeywords(new LocalizedKeywords(Locale.ENGLISH));
//		configuration.usePathCalculator(new AbsolutePathCalculator());
//		configuration.useParameterControls(new ParameterControls());
//		configuration.useParameterConverters(new ParameterConverters());
//		configuration.useParanamer(new NullParanamer());
//		configuration.usePendingStepStrategy(new PassingUponPendingStep());
//		configuration.useStepCollector(new MarkUnmatchedStepsAsPending());
//		configuration.useStepdocReporter(new PrintStreamStepdocReporter());
//		configuration.useStepFinder(new StepFinder());
//		configuration.useStepMonitor(new SilentStepMonitor());
//		configuration
//				.useStepPatternParser(new RegexPrefixCapturingPatternParser());
//		configuration.useStoryControls(new StoryControls());
//		configuration.useStoryLoader(new LoadFromClasspath());
//		configuration.useStoryParser(new RegexStoryParser(configuration
//				.keywords()));
//		configuration.useStoryPathResolver(new UnderscoredCamelCaseResolver());
//		configuration.useStoryReporterBuilder(new StoryReporterBuilder());
//		configuration.useViewGenerator(new FreemarkerViewGenerator());
// 
//		EmbedderControls embedderControls = configuredEmbedder()
//				.embedderControls();
//		embedderControls.doBatch(false);
//		embedderControls.doGenerateViewAfterStories(true);
//		embedderControls.doIgnoreFailureInStories(false);
//		embedderControls.doIgnoreFailureInView(false);
//		embedderControls.doSkip(false);
//		embedderControls.doVerboseFailures(false);
//		embedderControls.doVerboseFiltering(false);
//		embedderControls.useStoryTimeoutInSecs(300);
//		embedderControls.useThreads(1);
		
		configuration=new MostUsefulConfiguration()
        // where to find the stories
        .useStoryLoader(new LoadFromClasspath(this.getClass()))
        // CONSOLE and TXT reporting
        .useStoryReporterBuilder(
                new StoryReporterBuilder().withDefaultFormats()
                        .withFormats(Format.CONSOLE, Format.HTML).withCodeLocation(CodeLocations.codeLocationFromPath("jbehave")));
	}
	
	@Override
	public InjectableStepsFactory stepsFactory() {				
		return new InstanceStepsFactory(configuration(), new ExampleSteps(),new InstrumentSteps(),new HistorySteps());
	}
	
	@Override
	public Configuration configuration() {
		return configuration;
	}
	
	@Override
	protected List<String> storyPaths() {
		//return asList("story/*.story");
		StoryFinder finder = new StoryFinder();
        return finder.findPaths(codeLocationFromClass(this.getClass()).getFile(), asList("**/*.story"), asList(""));
	}
}